﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Caching;
using Aandelendelen.Obs;

namespace Aandelendelen.Caching
{
	public class CacheableRandom : Random, ICacheable
	{
		public static string CacheName = "data_random"; 

		public CacheableRandom()
			: base((int)(DateTime.Now.Ticks & 0xFFFFFFFF))
		{
			InitCacheKey();
		}

		public static CacheableRandom GetInstance()
		{
			return DataCache.GetCacheableObject<CacheableRandom>(CacheName);
		}

		public static CacheableRandom GetInstance(string cacheKey)
		{
			return DataCache.GetCacheableObject<CacheableRandom>(cacheKey);
		}

#region ICacheable 
		public CacheKey CacheKey { get; set; }

		public void CacheThis(string cacheKey)
		{
			this.CacheKey.CacheThis(cacheKey);
		}

		public void InitCacheKey()
		{
			CacheKey = new CacheKey()
			{
				SecondsBeforeInvalidate = 86400,
				ObjectToCache = this
			};
		}
#endregion
	}
}